package com.ybl.store.backend.config;

import com.ybl.store.backend.interceptor.JwtTokenAdminInterceptor;
import com.ybl.store.backend.interceptor.JwtTokenClerkInterceptor;
import com.ybl.store.backend.interceptor.JwtTokenManagerInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * WebMvc 配置
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    private final JwtTokenAdminInterceptor jwtTokenAdminInterceptor;

    private final JwtTokenManagerInterceptor jwtTokenManagerInterceptor;

    private final JwtTokenClerkInterceptor jwtTokenClerkInterceptor;

    /**
     * 注册拦截器
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/api/v1/backend/store/**")
                .excludePathPatterns("/api/v1/backend/store/list/name")
                .addPathPatterns("/api/v1/backend/clerk/**")
                .excludePathPatterns("/api/v1/backend/clerk/self/**")
                .excludePathPatterns("/api/v1/backend/clerk/list/name");

        registry.addInterceptor(jwtTokenManagerInterceptor)
                .addPathPatterns("/api/v1/backend/product/**")
                .excludePathPatterns("/api/v1/backend/product/list/name")
                .addPathPatterns("/api/v1/backend/log/product-number/**")
                .addPathPatterns("/api/v1/backend/voucher/**")
                .excludePathPatterns("/api/v1/backend/voucher/list/name");

        registry.addInterceptor(jwtTokenClerkInterceptor)
                .addPathPatterns("/api/v1/backend/user-info")
                .addPathPatterns("/api/v1/backend/customer/**")
                .addPathPatterns("/api/v1/backend/store/list/name")
                .addPathPatterns("/api/v1/backend/clerk/list/name")
                .addPathPatterns("/api/v1/backend/clerk/self/**")
                .addPathPatterns("/api/v1/backend/product/list/name")
                .addPathPatterns("/api/v1/backend/voucher/list/name")
                .addPathPatterns("/api/v1/backend/deal/product/**")
                .addPathPatterns("/api/v1/backend/log/deal/product-number/**")
                .addPathPatterns("/api/v1/backend/log/deal/product-payment/**")
                .addPathPatterns("/api/v1/backend/deal/voucher/**");
    }
}
